<!doctype html>

<html>
<head>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<?php
	include_once('navbar.php');
	include_once('superheader.php');
	
?>

<script>
$(function() {
	
    $( "#bck" ).button();
    $( "#button3" ).button();
});
    </script>
</head>

<body>
	
	<?php
		$currDate = date("m/d/Y");
		
		if ($_POST['type'] == "upManWk")
		{
			$searchDate = date('m/d/Y', strtotime("+7 days"));
			$range = array('schedDate' => array('$gte' => $currDate, '$lte' => $searchDate));
			print "<h2>Upcoming Maintenances - Week</h2>";
		}
		elseif ($_POST['type'] == "upManMo")
		{
			$searchDate = date('m/d/Y', strtotime("+1 months"));
			$range = array('schedDate' => array('$gte' => $currDate, '$lte' => $searchDate));
			print "<h2>Upcoming Maintenances - Month</h2>";
		}
		elseif ($_POST['type'] == "backManWk")
		{
			$searchDate = date('m/d/Y', strtotime("-7 days"));
			$range = array('schedDate' => array('$lte' => $currDate, '$gte' => $searchDate));
			print "<h2>Completed Maintenance - Past Week</h2>";
		}
		elseif ($_POST['type'] == "backManMo")
		{
			$searchDate = date('m/d/Y', strtotime("-1 months"));
			$range = array('schedDate' => array('$lte' => $currDate, '$gte' => $searchDate));
			print "<h2>Completed Maintenance - Past Month</h2>";
		}
		else 
		{
			$searchDate = date('m/d/Y', strtotime("+7 days"));
			$range = array('schedDate' => array('$gte' => $currDate, '$lte' => $searchDate));
			print "<h2>Upcoming Maintenances - Week</h2>";
		}
	?>
	<form>
	<div id="bck">
	<a href="report.php" ><id="nav1" name="radio"><label for="nav1">run another report</label></a>
	</div>
	</form>
	

	
	
	<table border="1" style="position: relative; top:2px; left:0px; height:25px">
		<?php
	        $z = new Mongo();
	        $db = $z->EMU;
	        $collection = $db->requests;
			$range = array('schedDate' => array('$gte' => $currDate, '$lte' => $searchDate));
			$newCursor = $collection->find($range);
	
			print "<tr>";
				print "<td>" . "Request #". "</td>";
				print "<td>" . "Assignee". "</td>";
				print "<td>" . "Requester". "</td>";
				print "<td>" . "Description". "</td>";
				print "<td>" . "Submitted Date". "</td>";
				print "<td>" . "Scheduled Date". "</td>";
			print "</tr>";
	
			foreach ($newCursor as $item) 
			{
				print "<tr>";
					print "<td>" . $item['ticketNum'] . "</td>";
					print "<td>" . $item['assignee'] . "</td>";;
					print "<td>" . $item['requester'] . "</td>";
					print "<td>" . $item['mDescription'] . "</td>";
					print "<td>" . $item['subDate'] . "</td>";
					print "<td>" . $item['schedDate'] . "</td>";
				print "</tr>";
			}
		?>
	</table>
</body>

</html>